package com.sunwayworld.basemodule.coredata.judgmentbasis.service.impl;

import com.sunwayworld.basemodule.coredata.judgmentbasis.bean.LimsJudgmentBasisTmAnalyteHighlowBean;
import com.sunwayworld.basemodule.coredata.judgmentbasis.dao.LimsJudgmentBasisTmAnalyteHighlowDao;
import com.sunwayworld.basemodule.coredata.judgmentbasis.service.LimsJudgmentBasisTmAnalyteHighlowService;
import com.sunwayworld.framework.at.annotation.AuditTrailEntry;
import com.sunwayworld.framework.at.annotation.AuditTrailType;
import com.sunwayworld.framework.context.ApplicationContextHelper;
import com.sunwayworld.framework.mybatis.mapper.MapperParameter;
import com.sunwayworld.framework.restful.data.RestJsonWrapperBean;
import com.sunwayworld.framework.spring.annotation.GikamBean;
import com.sunwayworld.framework.support.PersistableHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Repository
@GikamBean
public class LimsJudgmentBasisTmAnalyteHighlowServiceImpl implements LimsJudgmentBasisTmAnalyteHighlowService {

    @Autowired
    private LimsJudgmentBasisTmAnalyteHighlowDao limsJudgmentBasisTmAnalyteHighlowDao;

    @Override
    @SuppressWarnings("unchecked")
    public LimsJudgmentBasisTmAnalyteHighlowDao getDao() {
        return limsJudgmentBasisTmAnalyteHighlowDao;
    }

    @Override
    @Transactional
    @AuditTrailEntry(AuditTrailType.INSERT)
    public Long insert(RestJsonWrapperBean jsonWrapper) {
        LimsJudgmentBasisTmAnalyteHighlowBean limsJudgmentBasisTmAnalyteHighlow = jsonWrapper.parseUnique(LimsJudgmentBasisTmAnalyteHighlowBean.class);
        limsJudgmentBasisTmAnalyteHighlow.setId(ApplicationContextHelper.getNextIdentity());
        getDao().insert(limsJudgmentBasisTmAnalyteHighlow);
        return limsJudgmentBasisTmAnalyteHighlow.getId();
    }

    @Override
    public List<LimsJudgmentBasisTmAnalyteHighlowBean> selectHeighLowFullInfoList(MapperParameter parameter) {
        List<Map<String, Object>> mapList = getDao().selectHeighLowFullInfoList(parameter);
        if (mapList.isEmpty()) {
            return Collections.emptyList();
        }
        return mapList.stream().map(map -> PersistableHelper.mapToPersistable(map, LimsJudgmentBasisTmAnalyteHighlowBean.class)).collect(Collectors.toList());
    }
}
